<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        thead tr th{text-align: center!important;font-weight: bold!important;}
        tr td{text-align: center!important;}
        .input-this{
            background-color: #E1FFFF!important;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header" style="text-align: center;color: #0a6aa1">
                    <h3>点击库存、成本价与销售价单元格，进行数据编辑</h3>
                </div>
                <div class="layui-card-body">
                    <table lay-filter="parse-table-demo">
                        <thead>
                        <tr>
                            <th lay-data="{field:'index', width:40}">序号</th>
                            <th lay-data="{field:'id', width:60,sort:true}">ID</th>
                            <th lay-data="{field:'specName', minWidth:150}">规格名称</th>
                            <th lay-data="{field:'skuCode', minWidth:110}">SKU编码</th>
                            <th lay-data="{field:'qty', minWidth:80,sort:true,edit: 'number',style:'color:red'}" lay-filter="stock">库存</th>
                            <c:if test="${proType!=4}">
                                <th lay-data="{field:'cost', minWidth: 80,sort:true,edit: 'text',style:'color:red'}" lay-filter="cost">成本价</th>
                                <th lay-data="{field:'price', minWidth: 80,sort:true,edit: 'text',style:'color:red'}" lay-filter="price">销售价</th>
                                <c:if test="${proType==3}">
                                    <th lay-data="{field:'groupPrice', minWidth: 80,sort:true,edit: 'text',style:'color:red'}" lay-filter="groupPrice">团购价</th>
                                </c:if>
                            </c:if>
                            <c:if test="${proType==4}">
                                <th lay-data="{field:'point', minWidth: 80,sort:true,edit: 'text',style:'color:red'}" lay-filter="point">积分</th>
                            </c:if>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${skuList}" var="s" varStatus="ss">
                            <tr>
                                <td>${ss.index+1}</td>
                                <td>${s.id}</td>
                                <td>${s.specName}</td>
                                <td>${s.skuCode}</td>
                                <td>${s.qty}</td>
                                <c:if test="${s.proType!=4}">
                                    <td>${s.cost}</td>
                                    <c:if test="${s.proType==1 || s.proType==5}">
                                        <td>${s.price}</td>
                                    </c:if>
                                    <c:if test="${s.proType==3}">
                                        <td>${s.price}</td>
                                        <td>${s.groupPrice}</td>
                                    </c:if>
                                </c:if>
                                <c:if test="${s.proType==4}">
                                    <td>${s.point}</td>
                                </c:if>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var table = layui.table;
        var $ = layui.$, active = {
            parseTable: function(){
                //转化静态表格
                table.init('parse-table-demo', {
                });
            }
        };
        table.on('edit(parse-table-demo)', function(obj){
            //得到修改后的值
            var value = obj.value,oriData = obj.data;
            //得到字段
            var key = obj.field;
            var param = {"id":oriData.id,"index":oriData.index};
            param[key] = value;
            $.ajax({
                url: "/product/priceStockEdit",
                data: param,
                dataType: "json",
                type: "post",
                success: function (data) {
                    if(data.status){
                        layer.msg(oriData.skuCode + "更新成功，更新为 " + value,{icon:1});
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000)
                    }else{
                        layer.msg(oriData.skuCode + "的"+key+"更新失败，" + data.desc,{icon:2});
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000)
                    }
                }
            });
        });
        var type = "parseTable";
        active[type] && active[type].call(this);
    });
</script>
</body>
</html>